package com.asp.controller;

import com.asp.dto.AiAskDTO;
import com.asp.dto.PromptDTO;
import com.asp.entity.Dialogue;
import com.asp.entity.Prompt;
import com.asp.result.Result;
import com.asp.service.ConversationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author:          ndg
 * date:            2024/1/10
 */
@RestController
@RequestMapping("/user/ai")
@Api(tags = "ai对话相关接口")
@Slf4j
public class ConversationController {


    @Autowired
    private ConversationService conversationService;

    @PostMapping("/ask")
    @ApiOperation(value = "ai对话")
    public Result ask(@RequestBody AiAskDTO aiAskDTO) {
        log.info("ai对话：{}", aiAskDTO);
        String answer = conversationService.ask(aiAskDTO);
        return Result.success(answer);
    }


    @GetMapping("/dialogue")
    @ApiOperation(value = "对话回显")
    public Result dialogue() {
        log.info("对话回显");
        List<Dialogue> dialogueList = conversationService.dialogue();
        return Result.success(dialogueList);
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "用户删除对话 ")
    public Result delete() {
        log.info("用户删除对话");
        conversationService.delete();
        return Result.success();
    }


    @GetMapping("/prompt")
    @ApiOperation(value = "prompt 展示")
    public Result prompt() {
        log.info("prompt 展示");
        List<Prompt> promptList = conversationService.prompt();
        return Result.success(promptList);
    }


    @PostMapping("/promptAsk")
    @ApiOperation(value = "prompt 提问")
    public Result promptAsk(@RequestBody PromptDTO promptDTO) {
        log.info("用户prompt提问：{}", promptDTO);
        String answer = conversationService.promptAsk(promptDTO);
        return Result.success(answer);
    }
}
